<?php

/**
 * Created by PhpStorm.
 * User: li
 * Date: 15-10-18
 * Time: 下午10:57
 */
class Login extends MY_Api_Controller
{
    function __construct(){
        parent::__construct();
        $this->load->library('Api_auth');
    }
    /**
     * 登录接口
     */
    public function do_login()
    {
        $this->load->helper('validate');
        $account = $this->input->post('account');
        $password = $this->input->post('password');
        $device_id = $this->input->post('device_id');
        $device = $this->input->post('device');
        $check_mobile = is_mobile($account);
        $logined=false;
        if (!$check_mobile['status']) {
            $check_account = is_email($account);
            if (!$check_account['status']) {
                $this->set_response(10800);
            }else{
                $logined=$this->api_auth->login($account,$password,true,array($device,$device_id));
            }
        }else{
            $logined=$this->api_auth->login($account,$password,false,array($device,$device_id));
        }
        if (!$logined){
            $errors = $this->api_auth->get_error();
            if (isset($errors['banned'])) {								// banned user
                $this->set_response(20501);
            } elseif (isset($errors['not_activated'])) {				// not activated user
                $this->set_response(20502);
            } else {
                $this->set_response(20503);
            }
        }
        $this->set_response(0,array($this->api_auth->get_user()->user_id,$this->api_auth->get_token()));
    }

}